<?php
/**
 * Created by 绵阳人维网络科技有限公司.
 * User: 罗东华
 * Date: 2016/4/18
 * Time: 14:51
 */
namespace Admin\Logic;
class ConfigLogic extends AdminLogicBase{

    public function getConfig($id){

        $where['group']=$id;
        $config=M('config')->where($where)->order('sort ASC,id ASC')->select();
        return $config;

    }

    public function group(){

        $Config_group=S('Config_group');
        if($Config_group){ return $Config_group;}
        $g=config('CONFIG_GROUP_LIST');
        $gs=analysis($g);
        S('Config_group',$gs);
        return $gs;

    }
    /*遍历数据类型更新配置*/
    public function update_config($data=array()){
        if(!$data){$data=I('post.');}
        foreach($data as $key=> $v){
             $type=$this->field_type($key);
             $where['name']=$key;
             if($key=='CONFIG_GROUP_LIST'){ S('Config_group',null);}//清除分组缓存
             if($type==3 || $type==5){
                 M('config')->where($where)->save(array('extra'=>$v));
             }elseif($type==4){
                 M('config')->where($where)->save(array('extra'=>implode(':',$v)));
             }else{
                 M('config')->where($where)->save(array('value'=>$v));
             }

        }
        return true;

    }/*检查数据类型*/
    private function field_type($field){
        $where['name']=$field;
        return M('config')->where($where)->getField('type');
    }



}